(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('apf.dashboard.lastPaymentController', lastPaymentController);
	lastPaymentController.$inject = [ '$scope', '$q', 'Constants', 'panelConfig', 'layoutConfig', 'authService', 'validatorConfig', 'ChartJs', 'dashboardService', 'dashboardPanelService' ];
	function lastPaymentController($scope, $q, Constants, panelConfig, layoutConfig, authService, validatorConfig, ChartJs, dashboardService, dashboardPanelService) {
		var ctrl = this;
		ctrl.panelConfig = panelConfig;
		ctrl.panelConfig.helpMessages = [ ctrl.panelConfig.panelTitle + ' Help!!' ];
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.menus = [ {
			icon : 'remove',
			displayName : 'xxx.xxx.remove',
			action : 'remove'
		}, {
			icon : 'help',
			displayName : 'xxx.xxx.help',
			action : 'help'
		} ];
		ctrl.clickMenu = function(menu) {
			if (menu.action == 'remove') {
				dashboardPanelService.removePanel(ctrl.panelConfig);
			} else if (menu.action == 'help') {
				dashboardPanelService.showPanelHelp(ctrl.panelConfig);
			}
		};
		ctrl.chartConfig = {
			callback : {
				onClick : function(points, evt) {
					var ctx = evt.target.getContext('2d');
					console.log(points, ctx);
				}
			},
			options : {
				elements : {
					center : {
						onClick : function(chartController, config, event) {
							console.log(config);
						}
					},
					footer : {
						onClick : function(chartController, config, event) {
							console.log(config);
						}
					}
				}
			}
		};
		ctrl.$onInit = function() {
			dashboardService.getPagePanelData(panelConfig.pagePanelId).then(function(response) {
				angular.merge(ctrl.chartConfig, (response && response.panelData) ? response.panelData.chartData : {});
				if (ctrl.chartConfig.data && ctrl.chartConfig.data.length == 1 && angular.isArray(ctrl.chartConfig.data[0])) {
					ctrl.chartConfig.data = ctrl.chartConfig.data[0];
				}
			}, angular.noop);
		};

		$scope.$on('chart-create', function(event, chart) {
		});
		$scope.$on('chart-update', function(event, chart) {
		});
	}
})(angular);